
;[INSTALL]
; $tar zxvf cedet-1.0.tar.gz
; $make EMACS=emacs
; $mv cedet-1.0/ ~/.emacs.d/
(load-file "~/.emacs.d/cedet-1.0/common/cedet.el")

(semantic-load-enable-code-helpers)
;; choose my favarit minor-mode 
;(global-semantic-show-unmatched-syntax-mode 1)
(global-semantic-show-parser-state-mode 1)
;(global-semantic-highlight-edits-mode 1)
(global-semantic-highlight-func-mode 1)
(global-semantic-idle-local-symbol-highlight-mode 1)
(global-semantic-idle-completions-mode)

;; (setq semanticdb-project-roots (list (expand-file-name "/")))
(defconst cedet-user-include-dirs
  (list ".." "../include" "../inc" "../common" "../public"
        "../.." "../../include" "../../inc" "../../common" "../../public"))
(defconst cedet-win32-include-dirs
  (list "C:/MinGW/include"
        "C:/MinGW/include/c++/3.4.5"
        "C:/MinGW/include/c++/3.4.5/mingw32"
        "C:/MinGW/include/c++/3.4.5/backward"
        "C:/MinGW/lib/gcc/mingw32/3.4.5/include"
        "C:/Program Files/Microsoft Visual Studio/VC98/MFC/Include"))
(require 'semantic-c nil 'noerror)
(let ((include-dirs cedet-user-include-dirs))
  (when (eq system-type 'windows-nt)
    (setq include-dirs (append include-dirs cedet-win32-include-dirs)))
  (mapc (lambda (dir)
          (semantic-add-system-include dir 'c++-mode)
          (semantic-add-system-include dir 'c-mode))
        include-dirs))

;;[JUMP]
; jump to function declaration
;(define-key c-mode-base-map [S-f3] 'semantic-ia-fast-jump)
; jump between func declaration and definition
(define-key c-mode-base-map [S-f2] 'semantic-analyze-proto-impl-toggle)
; jump to last tag
(global-set-key [S-f3]
                (lambda ()
                  (interactive)
                  (if (ring-empty-p (oref semantic-mru-bookmark-ring ring))
                      (error "Semantic Bookmark ring is currently empty"))
                  (let* ((ring (oref semantic-mru-bookmark-ring ring))
                         (alist (semantic-mrub-ring-to-assoc-list ring))
                         (first (cdr (car alist))))
                    (if (semantic-equivalent-tag-p (oref first tag)
                                                   (semantic-current-tag))
                        (setq first (cdr (car (cdr alist)))))
                    (semantic-mrub-switch-tags first))))
;; [CEDET AUTO COMPLETION]
;; ;hippie-expand
;; (autoload 'senator-try-expand-semantic "senator")
;; (setq hippie-expand-try-functions-list
;;       '(
;;         senator-try-expand-semantic
;;         try-expand-dabbrev
;;         try-expand-dabbrev-visible
;;         try-expand-dabbrev-all-buffers
;;         try-expand-dabbrev-from-kill
;;         try-expand-list
;;         try-expand-list-all-buffers
;;         try-expand-line
;;         try-expand-line-all-buffers
;;         try-complete-file-name-partially
;;         try-complete-file-name
;;         try-expand-whole-kill
;;         )
;;       )
;; ; hippie-expand, use the semantic result first
;; (defun my-indent-or-complete ()
;;   (interactive)
;;   (if (looking-at "\\>")
;;       (hippie-expand nil)
;;     (indent-for-tab-command))
;;   )
;; ; hippie-expand for TAB
;; (define-key c-mode-base-map [(tab)] 'my-indent-or-complete)

; semantic expand(shift+tab)
(define-key c-mode-base-map (kbd "M-n") 'semantic-ia-complete-symbol-menu)

;[HIDE/SHOW]
(require 'semantic-tag-folding nil 'noerror)
(global-semantic-tag-folding-mode 1)
(define-key semantic-tag-folding-mode-map (kbd "M--") 'semantic-tag-folding-fold-block)
(define-key semantic-tag-folding-mode-map (kbd "M-=") 'semantic-tag-folding-show-block)
(define-key semantic-tag-folding-mode-map (kbd "s--") 'semantic-tag-folding-fold-all)
(define-key semantic-tag-folding-mode-map (kbd "s-=") 'semantic-tag-folding-show-all)
;toggle semantic-tag-folding, because this mode let it unable to set break point
;at fringe when debuging in gdb.
;(global-set-key (kbd "C-?") 'global-semantic-tag-folding-mode)

